home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 296_01.zip / CTOCXX.L < prev    next >
Text File  |  1993-04-01  |  8KB  |  220 lines

  1. D                       [0-9]
  2. L                       [a-zA-Z_]
  3. H                       [a-fA-F0-9]
  4. E                       [Ee][+-]?{D}+
  5. FS                      (f|F|l|L)
  6. IS                      (u|U|l|L)*
  7.  
  8. %{
  9. #include <stdio.h>
  10. #include "ytab.h"
  11. #include "ctocxx.h"
  12. extern int lineno;
  13. extern int edit_mode;
  14. char file_name[132] = {0};
  15.  
  16. void count();
  17. void pound();
  18. %}
  19.  
  20. %%
  21. "/*"                    { comment(); }
  22. "#line"                 { pound(); }
  23. "#"                     { pound(); }
  24. "near"                  { count(); /* ignore */ };
  25. "far"                   { count(); /* ignore */ };
  26. "cdecl"                 { count(); /* ignore */  };
  27. "..."                   { count(); return(INT); /*  ignore ... */ };
  28. "auto"                  { count(); return(AUTO); }
  29. "break"                 { count(); return(BREAK); }
  30. "case"                  { count(); return(CASE); }
  31. "char"                  { count(); return(CHAR); }
  32. "const"                 { count(); return(CONST); }
  33. "continue"              { count(); return(CONTINUE); }
  34. "default"               { count(); return(DEFAULT); }
  35. "do"                    { count(); return(DO); }
  36. "double"                { count(); return(DOUBLE); }
  37. "else"                  { count(); return(ELSE); }
  38. "enum"                  { count(); return(ENUM); }
  39. "extern"                { count(); return(EXTERN); }
  40. "float"                 { count(); return(FLOAT); }
  41. "for"                   { count(); return(FOR); }
  42. "goto"                  { count(); return(GOTO); }
  43. "if"                    { count(); return(IF); }
  44. "int"                   { count(); return(INT); }
  45. "long"                  { count(); return(LONG); }
  46. "register"              { count(); return(REGISTER); }
  47. "return"                { count(); return(RETURN); }
  48. "short"                 { count(); return(SHORT); }
  49. "signed"                { count(); return(SIGNED); }
  50. "sizeof"                { count(); return(SIZEOF); }
  51. "static"                { count(); return(STATIC); }
  52. "struct"                { count(); return(STRUCT); }
  53. "switch"                { count(); return(SWITCH); }
  54. "typedef"               { count(); return(TYPEDEF); }
  55. "union"                 { count(); return(UNION); }
  56. "unsigned"              { count(); return(UNSIGNED); }
  57. "void"                  { count(); return(VOID); }
  58. "volatile"              { count(); return(VOLATILE); }
  59. "while"                 { count(); return(WHILE); }
  60.  
  61. {L}({L}|{D})*           { count(); return(check_type()); }
  62.  
  63. 0[xX]{H}+{IS}?          { count(); return(CONSTANT); }
  64. 0[xX]{H}+{IS}?          { count(); return(CONSTANT); }
  65. 0{D}+{IS}?              { count(); return(CONSTANT); }
  66. 0{D}+{IS}?              { count(); return(CONSTANT); }
  67. {D}+{IS}?               { count(); return(CONSTANT); }
  68. {D}+{IS}?               { count(); return(CONSTANT); }
  69. '(\\.|[^\\'])+'         { count(); return(CONSTANT); }
  70.  
  71. {D}+{E}{FS}?            { count(); return(CONSTANT); }
  72. {D}*"."{D}+({E})?{FS}?  { count(); return(CONSTANT); }
  73. {D}+"."{D}*({E})?{FS}?  { count(); return(CONSTANT); }
  74.  
  75. \"(\\.|[^\\"])*\"       { count(); return(STRING_LITERAL); }
  76.  
  77. ">>="                   { count(); return(RIGHT_ASSIGN); }
  78. "<<="                   { count(); return(LEFT_ASSIGN); }
  79. "+="                    { count(); return(ADD_ASSIGN); }
  80. "-="                    { count(); return(SUB_ASSIGN); }
  81. "*="                    { count(); return(MUL_ASSIGN); }
  82. "/="                    { count(); return(DIV_ASSIGN); }
  83. "%="                    { count(); return(MOD_ASSIGN); }
  84. "&="                    { count(); return(AND_ASSIGN); }
  85. "^="                    { count(); return(XOR_ASSIGN); }
  86. "|="                    { count(); return(OR_ASSIGN); }
  87. ">>"                    { count(); return(RIGHT_OP); }
  88. "<<"                    { count(); return(LEFT_OP); }
  89. "++"                    { count(); return(INC_OP); }
  90. "--"                    { count(); return(DEC_OP); }
  91. "->"                    { count(); return(PTR_OP); }
  92. "&&"                    { count(); return(AND_OP); }
  93. "||"                    { count(); return(OR_OP); }
  94. "<="                    { count(); return(LE_OP); }
  95. ">="                    { count(); return(GE_OP); }
  96. "=="                    { count(); return(EQ_OP); }
  97. "!="                    { count(); return(NE_OP); }
  98. ";"                     { count(); return(';'); }
  99. "{"                     { count(); return('{'); }
  100. "}"                     { count(); return('}'); }
  101. ","                     { count(); return(','); }
  102. ":"                     { count(); return(':'); }
  103. "="                     { count(); return('='); }
  104. "("                     { count(); return('('); }
  105. ")"                     { count(); return(')'); }
  106. "["                     { count(); return('['); }
  107. "]"                     { count(); return(']'); }
  108. "."                     { count(); return('.'); }
  109. "&"                     { count(); return('&'); }
  110. "!"                     { count(); return('!'); }
  111. "~"                     { count(); return('~'); }
  112. "-"                     { count(); return('-'); }
  113. "+"                     { count(); return('+'); }
  114. "*"                     { count(); return('*'); }
  115. "/"                     { count(); return('/'); }
  116. "%"                     { count(); return('%'); }
  117. "<"                     { count(); return('<'); }
  118. ">"                     { count(); return('>'); }
  119. "^"                     { count(); return('^'); }
  120. "|"                     { count(); return('|'); }
  121. "?"                     { count(); return('?'); }
  122.  
  123. [ \t\v\f]               { count(); }
  124. [\n]                    { lineno++; count(); }
  125. .                       {; /* ignore bad characters */ }
  126.  
  127. %%
  128.  
  129. int yywrap()
  130.     {
  131.     return(1);
  132.     }
  133.  
  134. comment()
  135.     {
  136.     char c, c1;
  137.  
  138. loop:
  139.     while ((c = input()) != '*' && c != 0)
  140.         putchar(c);
  141.  
  142.     if ((c1 = input()) != '/' && c != 0)
  143.         {
  144.         unput(c1);
  145.         goto loop;
  146.         }
  147.  
  148.     if (c != 0)
  149.         putchar(c1);
  150.     }
  151.  
  152. int column = 0;
  153.  
  154. void count()
  155.     {
  156.     int i;
  157.  
  158.     for (i = 0; yytext[i] != '\0'; i++)
  159.         if (yytext[i] == '\n')
  160.             column = 0;
  161.         else if (yytext[i] == '\t')
  162.             column += 8 - (column % 8);
  163.         else
  164.             column++;
  165.  
  166.     stuff();
  167. /* for further debug remove comments from the ECHO macro below */
  168. /*  ECHO; */
  169.     }
  170.  
  171. /*-------------------------------------------------------------------*/
  172. /* lex_input and unput - routines callable elsewhere since input and  */
  173. /* unput are macros */
  174. lex_input() { return input(); }
  175.  
  176. lex_unput(ch) int ch; { unput(ch); }
  177.  
  178. /*-------------------------------------------------------------------*/
  179. /* pound - handles # lines, extracts line number and file name */
  180. void pound()
  181.     {
  182.     char c;
  183.     char buf[132];
  184.     int i = 0;
  185.     int num = 0;
  186.     extern FILE *efd;
  187.     static int first_time = TRUE;
  188.     char cur_file[132];
  189.  
  190.     while ( ( c=input() ) != '\n' && c != 0 )
  191.         buf[i++] = c;
  192.     buf[i] = '\0';
  193.     if ( (i = sscanf(buf,"%d %s",&num,cur_file)) == 2 )
  194.         {
  195.         if ( first_time )
  196.            {
  197.            strcpy(file_name,cur_file); 
  198.            first_time = FALSE;
  199.            }
  200.         if ( strcmp(file_name,cur_file) == 0 )
  201.             {
  202.             lineno = num;
  203.             edit_mode = TRUE;
  204.             }
  205.         else
  206.             edit_mode = FALSE;
  207.         }
  208.     else
  209.         fprintf(stderr,"#line couldn't convert into a number, %s\n",buf);
  210.     }
  211.  
  212. /*----------------------------------------------------------------*/
  213. int check_type()
  214.     {
  215.     if ( findsym(yytext) )  /* added by cdh to handle typedef names */
  216.         return(TYPE_NAME);  /* preloaded with int, char etc */
  217.     else
  218.         return(IDENTIFIER);
  219.     }
  220.